/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AIproccess;

import Army.building.Building;
import Army.ComputerTeam;
import Army.PlayerTeam;
import GameObject.LayerManager;
import java.awt.Point;

/**
 *
 * @author Huy
 */
public class PlayerAIActack extends PlayerAI {

	PlayerTeam targetTeam;

	public PlayerAIActack(LayerManager layer, ComputerTeam team) {
		super(layer, team);
		getTargetTeam();
		delay = 3000;
	}

	public void getTargetTeam() {
		int j1 = -1;// = (int) (Math.random() * layer.getListTeam().length);	 
		double d1 = 0;
		for (int j = 0; j < layer.getListTeam().length; j++) {
			if (layer.getListTeam()[j].getTeamId() != team.getTeamId() && layer.getListTeam()[j].isAlive()) {
				double d = team.getPosition().distance(layer.getListTeam()[j].getPosition());
				if (j1 == -1) {
					j1 = j;
					d1 = d;
				} else {
					if (d1 > d) {
						j1 = j;
						d1 = d;
					}
				}
			}
		}
		if (j1 == -1) {
			return;
		}
		targetTeam = layer.getListTeam()[j1];
	}

	public LayerManager getLayer() {
		return layer;
	}

	public void setLayer(LayerManager layer) {
		this.layer = layer;
	}



	protected Point getPosition(ComputerTeam team, int r) {
		int i = (int) (Math.random() * team.getListBuilding().size());
		if (i == team.getListBuilding().size()) {
			return new Point(0, 0);
		}
		Building base = team.getListBuilding().get(i);
		return new Point(base.getPosition().x + RANDOM.nextInt(2 * r) - r, base.getPosition().y + RANDOM.nextInt(2 * r) - r);
	}
}
